var carpark = carpark || {};

carpark.deleteRow = function(url, rows, success) {
	if(rows == null || rows.length <= 0) {
		return;
	}
	$.messager.confirm("删除提示", "确认删除选中的" + rows.length + "条记录吗？", function(t) {
		if(t) {
			var id = [];
			for(i = 0; i < rows.length; i++) {
				id.push(rows[i].id);
			}
			$.ajax({
				url: url,
				traditional: true,
				async: false,
				type: "post",
				dataType: "json",
				data: {
					'ids': id
				},
				success: function(data) {
					try{
						success(data)
					}catch(e){
						sy.info("删除操作完成回调时发生错误。"+e);
					}
				}
			});
		}
	});
}

carpark.checkUser = function(e, removeType) {
	$.post("/getUserInfo", function(user) {
		if(user.userType == removeType) {
			e.remove();
		} else {
			e.attr("style", "display: inline;")
		}
	});
}

carpark.initOperaNameCombox = function(combox) {
	$.post("/systemUser/list", function(data) {
		data.rows.unshift({
			userName: "全部"
		})
		combox.combobox({
			data: data.rows,
			valueField: 'userName',
			textField: 'userName'
		})
	})
}

$.fn.mygrid=function(data){
	var frozenColumns=data.frozenColumns;
	var columns=data.columns;
	for (var i in frozenColumns) {
		for (var j in frozenColumns[i]) {
			frozenColumns[i][j].sorter=function(a,b){  
				return (a + '').localeCompare(b + ''); 
			}
			frozenColumns[i][j].sortable=true;
		}
	}
	for (var i in columns) {
		for (var j in columns[i]) {
			columns[i][j].sorter=function(a,b){  
				return (a + '').localeCompare(b + ''); 
			}
			columns[i][j].sortable=true;
		}
	}
	data.frozenColumns=frozenColumns;
	data.columns=columns;
	var g={			title: '',
					striped: true,
					rownumbers: true,
					pagination: true,
					singleSelect: false,
					ctrlSelect: true,
					idField: 'id',
					remoteSort:false,
					pageSize: 50,
					pageList: [10, 20, 30, 40, 50, 100, 200, 300, 400, 500, 1000, 10000],
					frozenColumns: frozenColumns,
					columns: columns,
					toolbar: '#toolbar',

				}
	if(data!=null){
		$.extend(g, data);
	}
	
	return this.datagrid(g);
}

